package com.hs.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.hs.sfzy.entity.Consultant;
import com.hs.sfzy.service.ConsultantService;
import com.hs.sfzy.until.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName ConsultantController
 * @Description TODO
 * @Author wangzhihao
 * @Date 2025年08月13日 10:56
 * @Version 1.0
 */
@RestController
@RequestMapping("Consultant")
public class ConsultantController {
    @Autowired
    private ConsultantService consultantService;
    @PostMapping
    public R addConsultant(@RequestBody Consultant consultant) {
        int i = consultantService.addConsultant(consultant);
        if (i > 0) {
            return R.ok();
        }
        return R.fail();
    }
    @GetMapping("{id}")
    public R getConsultant(@PathVariable("id") int id ){
        Consultant consultant = consultantService.getConsultant(id);
        return R.ok(consultant);
    }
    @GetMapping("page")
    public R getConsultantPage(@RequestParam(required = false,defaultValue = "1") int pageNum,
                               @RequestParam(required = false,defaultValue = "10") int pageSize){
        PageInfo<Consultant> consultants = consultantService.getConsultants(pageNum,pageSize);
        return R.ok(consultants);
    }
    @GetMapping("pageTag")
    public R getConsultantPages(@RequestParam(required = false,defaultValue = "1") int pageNum,
                               @RequestParam(required = false,defaultValue = "10") int pageSize){
        PageInfo<Consultant> consultants = consultantService.getConsultants(pageNum,pageSize);
        return R.ok(consultants);
    }
    @GetMapping("pageslevtag")
    public R getConlevtag(Consultant consultant,
                          @RequestParam(required = false,defaultValue = "1") int pageNum,
                          @RequestParam(required = false,defaultValue = "6")int pageSize){
        PageInfo<Consultant> conlevtag = consultantService.getConlevtag(consultant, pageNum, pageSize);
        return R.ok(conlevtag);
    }
    @GetMapping("all")
    public R getAllConsultant(Consultant consultant){
        List<Consultant> byAll = consultantService.getByAll(consultant);
        return R.ok(byAll);
    }
    @GetMapping("getConAndLevAndTag")
    public R getConsultantsAndLevelAndTags(String levelName,String tag){
        List<Consultant> consultantsAndLevelAndTags = consultantService.getConsultantsAndLevelAndTags(levelName, tag);
        return R.ok(consultantsAndLevelAndTags);
    }
}
